#!/usr/bin/python

import sys
import re

sys.stdout.write(
'''----------------------------------------------------------------------------
This file contains an automatically generated listing of the functions
available in the Python API.
----------------------------------------------------------------------------

''')

file = open('pyjuku.cpp', 'r')

while file.readline().find('PyMethodDef JukuMethods') == -1:
	pass

file.readline()

def parse_doc(x):
	x = x.replace(r'\\', '\\')
	x = x.replace(r'\t', '\t')
	x = x.replace(r'\n', '\n\t')
	return x

#	{"msgbox_info", msgbox_info, METH_VARARGS, "msgbox_info(message, title)"},
#	{NULL, NULL, 0, NULL}

while True:
	line = file.readline()
	if line == '':
		break
	if line.find('{NULL') != -1:
		break;
	#sys.stdout.write(line)
	m = re.search(r'[ \t]*//[ \t]*{', line)
	if m != None:
		continue
	m = re.search(r'[ \t]*//[ \t]*method', line)
	if m != None:
		continue
	m = re.search('{.*,.*,.*,.*"(.*)".*},', line)
	if m != None:
		sys.stdout.write(m.group(1)+'\n')
		continue;
	m = re.search('method_noargs\((.*)\),', line)
	if m != None:
		sys.stdout.write(m.group(1)+'()\n')
		continue;
	m = re.search('method\((.*),.*"(.*)"\),', line)
	if m != None:
		sys.stdout.write(m.group(1)+'('+m.group(2)+')\n')
		continue;
	m = re.search('method_doc\((.*),.*"(.*)",.*"(.*)"\),', line)
	if m != None:
		sys.stdout.write(m.group(1)+'('+m.group(2)+')\n\t'+parse_doc(m.group(3))+'\n')
		continue;
	
	sys.stdout.write('unrecognized definition: '+line)

sys.stdout.write('\n')

